package com.lht.testDemo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;

/**
 * @author Eric
 * @version 1.0
 * @date 2020-01-13
 */
public class VarArgumentTest {

    public static void main(String[] args) {
        int total = 4 * 1000000;
        List<String> list = new ArrayList<>();
        for (int i = 0; i < total; i++) {
            list.add(UUID.randomUUID().toString());
        }
        System.out.println("开始测试-----------------------");
        Long start = System.nanoTime();
        for (int i = 0; i < total; i += 4) {
            test(list.get(i), list.get(i + 1), list.get(i + 2), list.get(i + 3));
        }
        Long end = System.nanoTime();
        long count = end - start;
        System.out.println("耗时 => " + count);

        System.out.println("动态开始测试-----------------------");
        start = System.nanoTime();
        for (int i = 0; i < total; i += 4) {
            testVar(list.get(i), list.get(i + 1), list.get(i + 2), list.get(i + 3));
        }
        end = System.nanoTime();
        count = end - start;
        System.out.println("耗时 => " + count);

    }

    public static void test(String one, String two, String three, String four) {
        StringBuilder sb = new StringBuilder();
        sb.append(one);
        sb.append(two);
        sb.append(three);
        sb.append(four);
    }


    public static void testVar(String... all) {
        StringBuilder sb = new StringBuilder();
        for (String a : all) {
            sb.append(a);
        }
    }

}
